import 'dart:convert';

import 'package:city_pickers/city_pickers.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/config.dart';
import 'package:yp/router.dart';
import 'package:yp/utils/util.dart';
import 'package:yp/widgets/select_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:kzcity_picker/kzcity_picker.dart';
import 'package:yp/pages/address_selector/cy_city_picker.dart';

import '../../helper.dart';
import 'logic.dart';
import 'state.dart';

class ApplyDetailPage extends StatelessWidget {
  final ApplyDetailLogic logic = Get.put(ApplyDetailLogic());
  final ApplyDetailState state = Get.find<ApplyDetailLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        iconTheme: IconThemeData(color: Colors.black),
        title: Text(
          "售后详情",
          style: TextStyle(color: Colors.black, fontSize: 32.sp),
        ),
        centerTitle: true,
        elevation: 0,
      ),
      body: GetBuilder<ApplyDetailLogic>(
        builder: (logic) {
          return state.detail == null
              ? Container()
              : Column(
                  children: [
                    Expanded(
                      child: ListView(
                        shrinkWrap: true,
                        primary: true,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              InkWell(
                                onTap: () {
                                  print('订单id222');
                                  print(state.id);
                                  Get.toNamed(RouteConfig.refundProgress,
                                      arguments: {'id': state.id});
                                },
                                child: Container(
                                  width: 750.w,
                                  decoration: BoxDecoration(
                                    color: Config.mainColor,
                                  ),
                                  padding:
                                      EdgeInsets.only(top: 40.w, bottom: 28.w),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      Container(
                                        child: RichText(
                                          text: TextSpan(
                                            style: TextStyle(
                                              color: Config.mainColor,
                                              fontSize: 32.w,
                                            ),
                                            children: [
                                              TextSpan(
                                                text:
                                                    '${state.detail['order_state_name']}',
                                                style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize: 32.w,
                                                ),
                                              ),
                                              WidgetSpan(
                                                child: SizedBox(
                                                  width: 5.w,
                                                ),
                                              ),
                                              TextSpan(
                                                text: '>',
                                                style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize: 32.w,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                      Container(
                                        height: 30.w,
                                        child: Text(
                                          "${state.time}",
                                          style: TextStyle(
                                            fontSize: 24.sp,
                                            color: Colors.white,
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              Container(
                                color: Colors.white,
                                padding: EdgeInsets.symmetric(
                                  vertical: 15,
                                  horizontal: 10,
                                ),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Container(
                                      width: 500.w,
                                      child: Column(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text(
                                                "订单编号：${state.detail['source_order_num_id']}",
                                                style: TextStyle(
                                                  fontSize: 24.sp,
                                                  color: Color(0xff666666),
                                                ),
                                              ),
                                              GestureDetector(
                                                onTap: () {
                                                  ClipboardData data =
                                                      new ClipboardData(
                                                          text: state.detail[
                                                              'source_order_num_id']);
                                                  Clipboard.setData(data);
                                                  toast("复制成功");
                                                },
                                                child: Container(
                                                  decoration: new BoxDecoration(
                                                      border: new Border.all(
                                                          color: Colors.grey,
                                                          width: 0.3),
                                                      borderRadius:
                                                          new BorderRadius
                                                                  .circular(
                                                              (20.0))),
                                                  child: Padding(
                                                    padding:
                                                        const EdgeInsets.only(
                                                            left: 8, right: 8),
                                                    child: Text(
                                                      "复制",
                                                      style: TextStyle(
                                                        fontSize: 24.sp,
                                                        color:
                                                            Color(0xff666666),
                                                      ),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text(
                                                "退货单号：${state.detail['order_num_id']}",
                                                style: TextStyle(
                                                  fontSize: 24.sp,
                                                  color: Color(0xff666666),
                                                ),
                                              ),
                                              GestureDetector(
                                                onTap: () {
                                                  ClipboardData data =
                                                      new ClipboardData(
                                                          text: state.detail[
                                                              'order_num_id']);
                                                  Clipboard.setData(data);
                                                  toast("复制成功");
                                                },
                                                child: Container(
                                                  decoration: new BoxDecoration(
                                                      border: new Border.all(
                                                          color: Colors.grey,
                                                          width: 0.3),
                                                      borderRadius:
                                                          new BorderRadius
                                                                  .circular(
                                                              (20.0))),
                                                  child: Padding(
                                                    padding:
                                                        const EdgeInsets.only(
                                                            left: 8, right: 8),
                                                    child: Text(
                                                      "复制",
                                                      style: TextStyle(
                                                        fontSize: 24.sp,
                                                        color:
                                                            Color(0xff666666),
                                                      ),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                          // Text(
                                          //   "退货单号：${state.detail['order_num_id']}",
                                          //   style: TextStyle(
                                          //     fontSize: 24.sp,
                                          //     color: Color(0xff666666),
                                          //   ),
                                          // ),
                                          Text(
                                            "申请时间：${state.detail['order_dtme']}",
                                            style: TextStyle(
                                              fontSize: 24.sp,
                                              color: Color(0xff666666),
                                            ),
                                          ),
                                          Text(
                                            "退款方式：${state.detail['so_sign_name']}",
                                            style: TextStyle(
                                              fontSize: 24.sp,
                                              color: Color(0xff666666),
                                            ),
                                          )
                                        ],
                                      ),
                                    ),
                                    SizedBox(
                                      width: 1,
                                      height: 50,
                                      child: DecoratedBox(
                                        decoration: BoxDecoration(
                                            color: Color(0xffD8D8D8)),
                                      ),
                                    ),
                                    Column(
                                      children: [
                                        Text(
                                          "预计退款",
                                          style: TextStyle(
                                            fontSize: 24.sp,
                                            color: Color(0xff000000),
                                          ),
                                        ),
                                        Text(
                                          "¥${state.detail['amount']['f_amount'].abs()}",
                                          style: TextStyle(
                                            fontSize: 24.sp,
                                            color: Color(0xff000000),
                                          ),
                                        )
                                      ],
                                    )
                                  ],
                                ),
                              ),
                              SizedBox(
                                width: 750.w,
                                height: 1,
                                child: DecoratedBox(
                                  decoration:
                                      BoxDecoration(color: Color(0xffefefef)),
                                ),
                              ),
                              Container(
                                width: 750.w,
                                color: Colors.white,
                                padding: EdgeInsets.symmetric(
                                  vertical: 20.w,
                                  horizontal: 20.w,
                                ),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      "预计退款详情：${state.detail['return_money_info']}",
                                      style: TextStyle(
                                        fontSize: 20.sp,
                                        color: Color(0xff999999),
                                      ),
                                    ),
                                    Visibility(
                                      visible: state.keFuString != '',
                                      child: GestureDetector(
                                        onTap: () {
                                          if (kIsWeb) {
                                            webpay(
                                                "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN");
                                            return;
                                          }
                                          gotoHelpDesk();
                                        },
                                        child: Image.asset(
                                          'assets/images/service_9.png',
                                          width: setWidth(40),
                                          height: setWidth(40),
                                          fit: BoxFit.cover,
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),

                              /// 商品
                              Column(
                                children: [
                                  ListView.separated(
                                    itemBuilder: (ctx, index) {
                                      var item =
                                          state.detail['order_items'][index];
                                      return Container(
                                        color: Colors.white,
                                        margin: EdgeInsets.symmetric(
                                          vertical: 20.w,
                                        ),
                                        padding: EdgeInsets.symmetric(
                                          vertical: 20.w,
                                          horizontal: 20.w,
                                        ),
                                        child: Row(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Container(
                                                width: 176.w,
                                                padding: EdgeInsets.only(
                                                    right: 16.w),
                                                child: Stack(
                                                  children: [
                                                    GestureDetector(
                                                      child: Image.network(
                                                        item['item_picture'],
                                                        width: 160.w,
                                                        height: 160.w,
                                                        fit: BoxFit.cover,
                                                      ),
                                                      onTap: () {
                                                        if (item[
                                                                'point_sale_type'] ==
                                                            0) {
                                                          Get.toNamed(
                                                              RouteConfig
                                                                  .goodsDetail,
                                                              arguments: {
                                                                'itemNumId': item[
                                                                        'item_num_id']
                                                                    .toString(),
                                                                'styleNumId': item[
                                                                        'style_num_id']
                                                                    .toString(),
                                                                // 'shopId': SpUtil.getInt('storeShopNum').toString(),
                                                                'shopId': item[
                                                                        'ec_shop_num_id']
                                                                    .toString(),
                                                                // 'ecStyleNumId': info['ec_style_num_id'].toString(),
                                                                'typeIndex': item[
                                                                    'is_pre_sale'],
                                                              });
                                                        }
                                                      },
                                                    ),
                                                  ],
                                                )),
                                            Expanded(
                                              child: Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                mainAxisAlignment:
                                                    MainAxisAlignment.start,
                                                children: [
                                                  Row(
                                                    children: [
                                                      if (item['pmt_sign'] == 1)
                                                        Container(
                                                          margin:
                                                              EdgeInsets.only(
                                                                  top: 6,
                                                                  right: 6),
                                                          padding: EdgeInsets
                                                              .fromLTRB(
                                                                  8, 3, 8, 3),
                                                          decoration: new BoxDecoration(
                                                              border: new Border.all(
                                                                  color: Color(
                                                                      0xFFFF0000),
                                                                  width: 0.5),
                                                              color: Colors.red,
                                                              borderRadius:
                                                                  new BorderRadius
                                                                          .circular(
                                                                      (9.0))),
                                                          alignment:
                                                              Alignment.center,
                                                          child: Text(
                                                            '赠品',
                                                            style: TextStyle(
                                                              fontSize: 18.sp,
                                                              color: Color(
                                                                  0xffffffff),
                                                            ),
                                                            maxLines: 1,
                                                            overflow:
                                                                TextOverflow
                                                                    .ellipsis,
                                                          ),
                                                        ),
                                                      Text(
                                                        item['item_name'],
                                                        style: TextStyle(
                                                          color:
                                                              Color(0xff333333),
                                                          fontSize: 28.w,
                                                        ),
                                                        maxLines: 1,
                                                        textAlign:
                                                            TextAlign.start,
                                                        overflow: TextOverflow
                                                            .ellipsis,
                                                      ),
                                                    ],
                                                  ),
                                                  SizedBox(
                                                    height: 40.w,
                                                  ),
                                                  Container(
                                                    width: 500.w,
                                                    child: Row(
                                                      mainAxisAlignment:
                                                          MainAxisAlignment
                                                              .spaceBetween,
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .end,
                                                      children: [
                                                        Text(
                                                          '¥${item['trade_price']}',
                                                          style: TextStyle(
                                                              color: Config
                                                                  .mainColor,
                                                              fontSize: 30.w),
                                                        ),
                                                        Text(
                                                          ' x${item['point_sale_type'] == 0 ? num.parse(item['qty'].toString()).abs().toInt() : num.parse(item['qty'].toString()).abs().toDouble().toStringAsFixed(2)}',
                                                          style: TextStyle(
                                                              color: Color(
                                                                  0xff222222),
                                                              fontSize: 24.w),
                                                        )
                                                      ],
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                      );
                                    },
                                    shrinkWrap: true,
                                    physics: NeverScrollableScrollPhysics(),
                                    itemCount:
                                        state.detail['order_items'].length,
                                    separatorBuilder:
                                        (BuildContext context, int index) {
                                      return SizedBox(height: 10.w);
                                    },
                                  ),
                                ],
                              ),

                              /// 退货方式
                              // state.detail['return_way']==2&&state.detail['operate_status_num_id']==90165||
                              //      state.detail['return_way']==2&&state.detail['operate_status_num_id']==90180||
                              //      state.detail['return_way']==2&&state.detail['operate_status_num_id']==90190||
                              //      state.detail['return_way']==2&&state.detail['operate_status_num_id']==90200||
                              //      state.detail['return_way']==2&&state.detail['operate_status_num_id']==90210
                              //  ?
                              //  Container(
                              //    color: Colors.white,
                              //    padding: EdgeInsets.symmetric(
                              //        vertical: 20.w, horizontal: 20.w),
                              //    child: Column(
                              //      crossAxisAlignment: CrossAxisAlignment.center,
                              //      mainAxisAlignment: MainAxisAlignment.start,
                              //      children: [
                              //        Row(
                              //          children: [
                              //            Text(
                              //              '退货方式',
                              //              style: TextStyle(
                              //                color: Color(0xff666666),
                              //                fontSize: 28.w,
                              //              ),
                              //            ),
                              //          ],
                              //        ),
                              //        SizedBox(
                              //          height: 15.w,
                              //        ),
                              //        Row(
                              //          mainAxisAlignment: MainAxisAlignment.start,
                              //          children: [
                              //            SelectButton(
                              //              title: "快递寄送",
                              //              isSelected: state.type == 1,
                              //              onTap: () => {
                              //                if(state.detail['return_way']==2&&state.detail['operate_status_num_id']==90165){
                              //                  logic.setType(1)
                              //                }
                              //              },
                              //            ),
                              //            SizedBox(width: 20.w),
                              //            SelectButton(
                              //              title: "自送上门",
                              //              isSelected: state.type == 2,
                              //              onTap: () => {
                              //                if(state.detail['return_way']==2&&state.detail['operate_status_num_id']==90165){
                              //                  logic.setType(2)
                              //                }
                              //              },
                              //            ),
                              //          ],
                              //        )
                              //      ],
                              //    ),
                              //  ):Container(
                              //   color: Colors.white,
                              //   padding: EdgeInsets.symmetric(
                              //       vertical: 20.w, horizontal: 20.w),
                              //   child: Column(
                              //     crossAxisAlignment: CrossAxisAlignment.center,
                              //     mainAxisAlignment: MainAxisAlignment.start,
                              //     children: [
                              //       Row(
                              //         children: [
                              //           Text(
                              //             '退货方式',
                              //             style: TextStyle(
                              //               color: Color(0xff666666),
                              //               fontSize: 28.w,
                              //             ),
                              //           ),
                              //         ],
                              //       ),
                              //       SizedBox(
                              //         height: 15.w,
                              //       ),
                              //       Row(
                              //         mainAxisAlignment:
                              //         MainAxisAlignment.start,
                              //         children: [
                              //           SelectButton(
                              //             title:
                              //             "${state.detail['so_sign_name']}",
                              //             isSelected: true,
                              //           ),
                              //           SizedBox(width: 20.w),
                              //         ],
                              //       )
                              //     ],
                              //   ),
                              // ),

                              SizedBox(
                                width: 750.w,
                                height: 1,
                                child: DecoratedBox(
                                  decoration:
                                      BoxDecoration(color: Color(0xffefefef)),
                                ),
                              ),

                              /// 寄回地址
                              if (state.detail['return_way'] == 2 && state.detail['operate_status_num_id'] == 90165 ||
                                  state.detail['return_way'] == 2 &&
                                      state.detail['operate_status_num_id'] ==
                                          90180 ||
                                  state.detail['return_way'] == 2 &&
                                      state.detail['operate_status_num_id'] ==
                                          90190 ||
                                  state.detail['return_way'] == 2 &&
                                      state.detail['operate_status_num_id'] ==
                                          90200 ||
                                  state.detail['return_way'] == 2 &&
                                      state.detail['operate_status_num_id'] ==
                                          90210)
                                Column(
                                  children: [
                                    InkWell(
                                      onTap: () {
                                        if (state.detail[
                                                'operate_status_num_id'] ==
                                            90165) {
                                          _clickEventFunc(context);

                                          // return _clickEventFunc(context);

                                        }
                                      },
                                      child: Container(
                                        color: Colors.white,
                                        padding: EdgeInsets.symmetric(
                                            vertical: 20.w, horizontal: 20.w),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Row(
                                              children: [
                                                Text(
                                                  '寄回地址',
                                                  style: TextStyle(
                                                    color: Color(0xff666666),
                                                    fontSize: 28.w,
                                                  ),
                                                ),
                                                SizedBox(
                                                  width: 30.w,
                                                ),
                                                Container(
                                                  width: 550.w,
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                    children: [
                                                      Text(
                                                        // state.provinceName !=
                                                        //         null
                                                        //     ? '${state.provinceName} ${state.cityName} ${state.areaName}${state.townName == null ? "" : " ${state.townName}"}'
                                                        //     : '请选择省市区',
                                                        state.return_prv_name !=
                                                                null
                                                            ? '${state.return_prv_name}${state.return_city_name}${state.return_city_area_name}'
                                                            : '请选择省市区',
                                                        style: TextStyle(
                                                          color: state.return_prv_name !=
                                                                  null
                                                              ? Color(
                                                                  0xff000000)
                                                              : Color(
                                                                  0xffcccccc),
                                                          fontSize: 28.w,
                                                        ),
                                                      ),
                                                      Icon(
                                                        Icons
                                                            .arrow_forward_ios_rounded,
                                                        size: 16,
                                                        color:
                                                            Color(0xffcccccc),
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),

                                    SizedBox(
                                      width: 750.w,
                                      height: 1,
                                      child: DecoratedBox(
                                        decoration: BoxDecoration(
                                            color: Color(0xffefefef)),
                                      ),
                                    ),

                                    /// 详细地址
                                    Container(
                                      color: Colors.white,
                                      padding: EdgeInsets.symmetric(
                                          vertical: 10.w, horizontal: 20.w),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Row(
                                            children: [
                                              Text(
                                                '详细地址',
                                                style: TextStyle(
                                                  color: Color(0xff666666),
                                                  fontSize: 28.w,
                                                ),
                                              ),
                                              SizedBox(
                                                width: 30.w,
                                              ),
                                              Container(
                                                width: 500.w,
                                                child: TextField(
                                                  enabled: state.detail[
                                                              'operate_status_num_id'] ==
                                                          90165
                                                      ? true
                                                      : false,
                                                  controller: state.controller,
                                                  textAlignVertical:
                                                      TextAlignVertical.center,
                                                  onChanged: (value) {},
                                                  decoration: InputDecoration(
                                                    isDense: true,
                                                    border: InputBorder.none,
                                                    hintText: '请填写详细地址',
                                                    hintStyle: TextStyle(
                                                      fontSize: 28.sp,
                                                      color: Color(0xffcccccc),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                    SizedBox(
                                      width: 750.w,
                                      height: 1,
                                      child: DecoratedBox(
                                        decoration: BoxDecoration(
                                            color: Color(0xffefefef)),
                                      ),
                                    ),

                                    /// 联系人
                                    Container(
                                      color: Colors.white,
                                      padding: EdgeInsets.symmetric(
                                          vertical: 10.w, horizontal: 20.w),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Row(
                                            children: [
                                              Text(
                                                '收货人',
                                                style: TextStyle(
                                                  color: Color(0xff666666),
                                                  fontSize: 28.w,
                                                ),
                                              ),
                                              SizedBox(
                                                width: 60.w,
                                              ),
                                              Container(
                                                width: 500.w,
                                                child: TextField(
                                                  enabled: state.detail[
                                                              'operate_status_num_id'] ==
                                                          90165
                                                      ? true
                                                      : false,
                                                  controller: state.controller1,
                                                  textAlignVertical:
                                                      TextAlignVertical.center,
                                                  onChanged: (value) {},
                                                  decoration: InputDecoration(
                                                    isDense: true,
                                                    border: InputBorder.none,
                                                    hintText: '请填写收货人',
                                                    hintStyle: TextStyle(
                                                      fontSize: 28.sp,
                                                      color: Color(0xffcccccc),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                    SizedBox(
                                      width: 750.w,
                                      height: 1,
                                      child: DecoratedBox(
                                        decoration: BoxDecoration(
                                            color: Color(0xffefefef)),
                                      ),
                                    ),

                                    /// 联系方式
                                    Container(
                                      color: Colors.white,
                                      padding: EdgeInsets.symmetric(
                                          vertical: 10.w, horizontal: 20.w),
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Row(
                                            children: [
                                              Text(
                                                '联系方式',
                                                style: TextStyle(
                                                  color: Color(0xff666666),
                                                  fontSize: 28.w,
                                                ),
                                              ),
                                              SizedBox(
                                                width: 30.w,
                                              ),
                                              Container(
                                                width: 500.w,
                                                child: TextField(
                                                  enabled: state.detail[
                                                              'operate_status_num_id'] ==
                                                          90165
                                                      ? true
                                                      : false,
                                                  controller: state.controller2,
                                                  textAlignVertical:
                                                      TextAlignVertical.center,
                                                  onChanged: (value) {},
                                                  decoration: InputDecoration(
                                                    isDense: true,
                                                    border: InputBorder.none,
                                                    hintText: '请填写联系方式',
                                                    hintStyle: TextStyle(
                                                      fontSize: 28.sp,
                                                      color: Color(0xffcccccc),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ],
                                      ),
                                    ),
                                    SizedBox(
                                      width: 750.w,
                                      height: 1,
                                      child: DecoratedBox(
                                        decoration: BoxDecoration(
                                            color: Color(0xffefefef)),
                                      ),
                                    ),

                                    /// 快递公司
                                    if (state.type == 1)
                                      InkWell(
                                        onTap: () {
                                          if (state.value == null) {
                                            showBottomSheet(context);
                                          }
                                        },
                                        child: Container(
                                          color: Colors.white,
                                          padding: EdgeInsets.symmetric(
                                              vertical: 20.w, horizontal: 20.w),
                                          child: Column(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.center,
                                            mainAxisAlignment:
                                                MainAxisAlignment.start,
                                            children: [
                                              Row(
                                                children: [
                                                  Text(
                                                    '快递公司',
                                                    style: TextStyle(
                                                      color: Color(0xff666666),
                                                      fontSize: 28.w,
                                                    ),
                                                  ),
                                                  SizedBox(
                                                    width: 30.w,
                                                  ),
                                                  Container(
                                                    width: 550.w,
                                                    child: Row(
                                                      mainAxisAlignment:
                                                          MainAxisAlignment
                                                              .spaceBetween,
                                                      children: [
                                                        Text(
                                                          state.value != null
                                                              ? state.value
                                                              : '请选择',
                                                          style: TextStyle(
                                                            color: state.value !=
                                                                    null
                                                                ? Color(
                                                                    0xff000000)
                                                                : Color(
                                                                    0xffcccccc),
                                                            fontSize: 28.w,
                                                          ),
                                                        ),
                                                        Icon(
                                                          Icons
                                                              .arrow_forward_ios_rounded,
                                                          size: 16,
                                                          color:
                                                              Color(0xffcccccc),
                                                        ),
                                                      ],
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                    if (state.type == 1)
                                      SizedBox(
                                        width: 750.w,
                                        height: 1,
                                        child: DecoratedBox(
                                          decoration: BoxDecoration(
                                              color: Color(0xffefefef)),
                                        ),
                                      ),

                                    /// 快递单号
                                    if (state.type == 1)
                                      Container(
                                        color: Colors.white,
                                        padding: EdgeInsets.symmetric(
                                            vertical: 10.w, horizontal: 20.w),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Row(
                                              children: [
                                                Text(
                                                  '快递单号',
                                                  style: TextStyle(
                                                    color: Color(0xff666666),
                                                    fontSize: 28.w,
                                                  ),
                                                ),
                                                SizedBox(
                                                  width: 30.w,
                                                ),
                                                Container(
                                                  width: 500.w,
                                                  child: TextField(
                                                    enabled: state.controller3
                                                                .text ==
                                                            ''
                                                        ? true
                                                        : false,
                                                    controller:
                                                        state.controller3,
                                                    textAlignVertical:
                                                        TextAlignVertical
                                                            .center,
                                                    onChanged: (value) {},
                                                    decoration: InputDecoration(
                                                      isDense: true,
                                                      border: InputBorder.none,
                                                      hintText: '请填写快递单号',
                                                      hintStyle: TextStyle(
                                                        fontSize: 28.sp,
                                                        color:
                                                            Color(0xffcccccc),
                                                      ),
                                                    ),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    if (state.type == 1)
                                      SizedBox(
                                        width: 750.w,
                                        height: 1,
                                        child: DecoratedBox(
                                          decoration: BoxDecoration(
                                              color: Color(0xffefefef)),
                                        ),
                                      ),

                                    /// 备注
                                    // Container(
                                    //   color: Colors.white,
                                    //   margin: EdgeInsets.only(top: 3.w),
                                    //   padding: EdgeInsets.symmetric(
                                    //       vertical: 20.w, horizontal: 20.w),
                                    //   child: Column(
                                    //     crossAxisAlignment:
                                    //         CrossAxisAlignment.center,
                                    //     mainAxisAlignment:
                                    //         MainAxisAlignment.start,
                                    //     children: [
                                    //       Row(
                                    //         children: [
                                    //           Text(
                                    //             '备注',
                                    //             style: TextStyle(
                                    //               color: Color(0xff666666),
                                    //               fontSize: 28.w,
                                    //             ),
                                    //           ),
                                    //         ],
                                    //       ),
                                    //       Container(
                                    //         color: Colors.white,
                                    //         child: Column(
                                    //           children: [
                                    //             Container(
                                    //               height: 100.w,
                                    //               child: TextField(
                                    //                 maxLines: 4,
                                    //                 // minLines: 1,
                                    //                 // maxLength: 5,
                                    //                 controller: state.controller4,
                                    //                 textAlignVertical:
                                    //                     TextAlignVertical.center,
                                    //                 decoration: InputDecoration(
                                    //                   isDense: true,
                                    //                   contentPadding:
                                    //                       EdgeInsets.all(0),
                                    //                   prefixIconConstraints:
                                    //                       BoxConstraints(
                                    //                     maxWidth: 70.w,
                                    //                     minWidth: 70.w,
                                    //                   ),
                                    //                   hintText: '请填写备注',
                                    //                   hintStyle: TextStyle(
                                    //                     fontSize: 24.sp,
                                    //                     color: Color(0xff999999),
                                    //                   ),
                                    //                   border: InputBorder.none,
                                    //                 ),
                                    //               ),
                                    //             ),
                                    //           ],
                                    //         ),
                                    //       ),
                                    //     ],
                                    //   ),
                                    // ),
                                  ],
                                ),

                              /// 寄回商品
                              // if(state.detail['return_way']==2&&state.detail['operate_status_num_id']==90165||
                              //     state.detail['return_way']==2&&state.detail['operate_status_num_id']==90180||
                              //     state.detail['return_way']==2&&state.detail['operate_status_num_id']==90190||
                              //     state.detail['return_way']==2&&state.detail['operate_status_num_id']==90200||
                              //     state.detail['return_way']==2&&state.detail['operate_status_num_id']==90210
                              // )
                              // Column(
                              //   crossAxisAlignment: CrossAxisAlignment.start,
                              //   children: [
                              //     Container(
                              //       margin: EdgeInsets.only(
                              //         top:10,
                              //         left:10,
                              //       ),
                              //       child: Text(
                              //         '寄回商品',
                              //         style: TextStyle(
                              //           color: Color(0xff666666),
                              //           fontSize: 28.w,
                              //         ),
                              //       ),
                              //     ),
                              //     SizedBox(
                              //       height: 10.w,
                              //     ),
                              //     ListView.separated(
                              //       itemBuilder: (ctx, index) {
                              //         var item = state.detail['order_items'][index];
                              //         return  Container(
                              //           color: Colors.white,
                              //           margin: EdgeInsets.symmetric(
                              //             vertical: 20.w,
                              //           ),
                              //           padding: EdgeInsets.symmetric(
                              //             vertical: 20.w,
                              //             horizontal: 20.w,
                              //           ),
                              //           child: Row(
                              //             crossAxisAlignment: CrossAxisAlignment.center,
                              //             mainAxisAlignment: MainAxisAlignment.start,
                              //             children: [
                              //               Container(
                              //                   width: 176.w,
                              //                   padding: EdgeInsets.only(right: 16.w),
                              //                   child: Stack(
                              //                     children: [
                              //                       Image.network(
                              //                         item['item_picture'],
                              //                         width: 160.w,
                              //                         height: 160.w,
                              //                         fit: BoxFit.cover,
                              //                       ),
                              //                     ],
                              //                   )),
                              //               Expanded(
                              //                 child: Column(
                              //                   crossAxisAlignment:
                              //                   CrossAxisAlignment.start,
                              //                   mainAxisAlignment:
                              //                   MainAxisAlignment.start,
                              //                   children: [
                              //                     Text(
                              //                       item['item_name'],
                              //                       style: TextStyle(
                              //                         color: Color(0xff333333),
                              //                         fontSize: 28.w,
                              //                       ),
                              //                       maxLines: 1,
                              //                       textAlign: TextAlign.start,
                              //                       overflow: TextOverflow.ellipsis,
                              //                     ),
                              //                     SizedBox(
                              //                       height: 40.w,
                              //                     ),
                              //                     Container(
                              //                       width: 500.w,
                              //                       child: Row(
                              //                         mainAxisAlignment:
                              //                         MainAxisAlignment
                              //                             .spaceBetween,
                              //                         crossAxisAlignment:
                              //                         CrossAxisAlignment.end,
                              //                         children: [
                              //                           Text(
                              //                             '¥${item['trade_price']}',
                              //                             style: TextStyle(
                              //                                 color: Config.mainColor,
                              //                                 fontSize: 30.w),
                              //                           ),
                              //                           Text(
                              //                             'x${num.parse(item['qty'].toString()).abs().toInt()}',
                              //                             style: TextStyle(
                              //                                 color: Color(0xff222222),
                              //                                 fontSize: 24.w),
                              //                           )
                              //                         ],
                              //                       ),
                              //                     ),
                              //                   ],
                              //                 ),
                              //               ),
                              //             ],
                              //           ),
                              //         );
                              //       },
                              //       shrinkWrap: true,
                              //       physics: NeverScrollableScrollPhysics(),
                              //       itemCount: state.detail['order_items'].length, separatorBuilder: (BuildContext context, int index) { return SizedBox(height: 10.w); },
                              //     ),
                              //   ],
                              // ),

                              /// 退货原因
                              Container(
                                color: Colors.white,
                                padding: EdgeInsets.symmetric(
                                    vertical: 20.w, horizontal: 20.w),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Row(
                                      children: [
                                        Text(
                                          '退货原因',
                                          style: TextStyle(
                                            color: Color(0xff999999),
                                            fontSize: 28.w,
                                          ),
                                        ),
                                        SizedBox(
                                          width: 15.w,
                                        ),
                                        Text(
                                          '${state.detail['back_type_name']}',
                                          style: TextStyle(
                                            color: Color(0xff333333),
                                            fontSize: 28.w,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(
                                width: 750.w,
                                height: 1,
                                child: DecoratedBox(
                                  decoration:
                                      BoxDecoration(color: Color(0xffefefef)),
                                ),
                              ),

                              /// 问题描述
                              Container(
                                width: 750.w,
                                color: Colors.white,
                                padding: EdgeInsets.symmetric(
                                  vertical: 20.w,
                                  horizontal: 20.w,
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Text(
                                      '问题描述',
                                      style: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 28.w,
                                      ),
                                    ),
                                    SizedBox(
                                      height: 20.w,
                                    ),
                                    Container(
                                      child: Text(
                                        '${state.detail['back_reason']}',
                                        style: TextStyle(
                                          color: Color(0xff333333),
                                          fontSize: 28.w,
                                        ),
                                      ),
                                    ),
                                    SizedBox(
                                      height: 50.w,
                                    ),
                                    if (state.img.length > 0)
                                      Container(
                                          width: 750.w,
                                          margin: EdgeInsets.only(
                                            top: 20.w,
                                          ),
                                          child: Wrap(
                                            children: imageListFun(state.img),
                                          )),
                                  ],
                                ),
                              ),
                              if (state.detail['order_state_name'] == '待商家审核')
                                GestureDetector(
                                  onTap: () {
                                    logic.submit();
                                  },
                                  child: Container(
                                    width: 750.w,
                                    height: 80.w,
                                    margin: EdgeInsets.symmetric(
                                      vertical: 40.w,
                                      horizontal: 20.w,
                                    ),
                                    decoration: BoxDecoration(
                                      color: Config.mainColor,
                                      borderRadius: BorderRadius.circular(40.w),
                                    ),
                                    child: Center(
                                      child: Text(
                                        "撤销申请",
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 28.w,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              if (state.detail['return_way'] == 2 &&
                                  state.detail['operate_status_num_id'] ==
                                      90165)
                                GestureDetector(
                                  onTap: () {
                                    logic.submitReturn();
                                  },
                                  child: Container(
                                    width: 750.w,
                                    height: 80.w,
                                    margin: EdgeInsets.symmetric(
                                      vertical: 40.w,
                                      horizontal: 20.w,
                                    ),
                                    decoration: BoxDecoration(
                                      color: Config.mainColor,
                                      borderRadius: BorderRadius.circular(40.w),
                                    ),
                                    child: Center(
                                      child: Text(
                                        "提交资料",
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 28.w,
                                        ),
                                      ),
                                    ),
                                  ),
                                )
                            ],
                          )
                        ],
                      ),
                    ),
                  ],
                );
        },
      ),
    );
  }
  gotoHelpDesk() {
    if (SpUtil.getString('token') == null ||
        SpUtil.getString('token').isEmpty) {
      Get.toNamed(RouteConfig.mallLogin,
      ).then((value) {
        if (SpUtil.getString('token') != null &&
            SpUtil.getString('token').isNotEmpty) {

        }
      });
    } else {
      if (state.keFuString.isNotEmpty) {
        var otherParams = {
          "productInfo": {},
          // "peerId": "10052439",
          "nickName": "${SpUtil.getString('empeName')}",
        };
        var clientId = '${SpUtil.getInt('empeNumId')}';
        var kefubaseUrl =
            'https://7moor.zrhsh.com/wapchat.html?fromUrl=&urlTitle=&language=ZHCN';
        kefubaseUrl = kefubaseUrl +
            '&accessId=' +
            state.keFuString +
            '&otherParams=' +
            jsonEncode(otherParams) +
            '&clientId=' +
            clientId;

        Get.toNamed(RouteConfig.webview, arguments: {
          "url":
          kefubaseUrl,
        });
      }
    }
  }
  List<Widget> imageListFun(List images) {
    var list2 = images
        .asMap()
        .map((index, item) {
          Widget widget = Image.network(
            '${item}',
            width: 100,
            height: 100,
          );
          return MapEntry(index, _createGridViewItem(widget, index));
        })
        .values
        .toList();

    List<Widget> list = List<Widget>.from(list2);

    return list;
  }

  //图片展示
  _createGridViewItem(widget, index) {
    return Container(
      height: 100.w,
      width: 100.w,
      color: Color(0xff999999),
      margin: EdgeInsets.only(right: 20.w, bottom: 20.w),
      child: widget,
    );
  }

  ///显示底部弹框的功能
  void showBottomSheet(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      builder: (BuildContext context) {
        //构建弹框中的内容
        return SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.only(
                bottom: MediaQuery.of(context).viewInsets.bottom),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(
                Radius.circular(25.w),
              ),
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Color(0xFFEA5504).withOpacity(.149),
                  offset: Offset(0, 0), //阴影y轴偏移量
                  blurRadius: 1,
                  spreadRadius: .3,
                )
              ],
            ),
            child: Column(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(
                    vertical: 36.w,
                    horizontal: 30.w,
                  ),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              "",
                              style: TextStyle(
                                color: Color(0xff999999),
                                fontSize: 28.sp,
                              ),
                            ),
                          ),
                          Text(
                            "快递公司",
                            style: TextStyle(
                              color: Color(0xff666666),
                              fontSize: 28.sp,
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Image.asset(
                              "assets/images/close2.png",
                              width: 44.w,
                            ),
                          ),
                        ],
                      ),
                      GetBuilder<ApplyDetailLogic>(
                        builder: (logic) {
                          return Container(
                            height: 700.w,
                            child: Container(
                              margin: EdgeInsets.only(
                                top: 20.w,
                              ),
                              padding: EdgeInsets.symmetric(
                                horizontal: 20.w,
                              ),
                              child: ListView.builder(
                                shrinkWrap: true,
                                itemBuilder: (ctx, i) {
                                  var item = state.kdList[i];
                                  return InkWell(
                                    onTap: () {
                                      logic.select(i);
                                    },
                                    child: Container(
                                      padding:
                                          EdgeInsets.symmetric(vertical: 25.w),
                                      decoration: BoxDecoration(
                                          border: Border(
                                              bottom: BorderSide(
                                                  color: Color(0xffefefef)))),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Expanded(
                                            child: Text(
                                              item['value'] ?? '1111',
                                              style: TextStyle(
                                                color: Color(0xff222222),
                                                fontSize: 24.sp,
                                              ),
                                              maxLines: 2,
                                              textAlign: TextAlign.start,
                                              overflow: TextOverflow.ellipsis,
                                            ),
                                          ),
                                          item['selected']
                                              ? Image(
                                                  image: AssetImage(
                                                      "assets/images/selectIcon1.png"),
                                                  width: 36.w,
                                                )
                                              : Image(
                                                  image: AssetImage(
                                                      "assets/images/save.png"),
                                                  width: 36.w,
                                                ),
                                        ],
                                      ),
                                    ),
                                  );
                                },
                                itemCount: state.kdList.length,
                              ),
                            ),
                          );
                        },
                      ),
                      SimpleDialogOption(
                        child: Container(
                          color: Colors.white,
                          child: GetBuilder<ApplyDetailLogic>(
                            builder: (logic) {
                              return GestureDetector(
                                onTap: () {
                                  logic.submitKd();
                                  Navigator.of(context).pop();
                                },
                                child: Container(
                                  width: 750.w,
                                  height: 80.w,
                                  decoration: BoxDecoration(
                                    color: Config.mainColor,
                                    borderRadius: BorderRadius.circular(40.w),
                                  ),
                                  child: Center(
                                    child: Text(
                                      "确定",
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 28.w,
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
      context: context,
    );
  }

  Result resultArr = new Result();

  void _clickEventFunc(context) async {
    final res = await KzcityPicker.showPicker(
      context,
      datas: state.addressList,
    );
    if (res != null) {
      // 刷新
      logic.selectCity(res);
    }

    // XYZCityPicker.showPicker(
    //     province: state.province,
    //     city: state.city,
    //     district: state.district,
    //     street: state.street,
    //     provinceListBack: state.provinceList,
    //     cityListBack: state.cityList,
    //     cityAreaListBack: state.cityAreaList,
    //     townListBack: state.townList,
    //     context: context,
    //     onChange: (int index, Map checkedItem, List backAddressItemList) {
    //       logic.selectCity(index, checkedItem, backAddressItemList);
    //     });
  }
// void _clickEventFunc(context) async {
//   Result tempResult = await CityPickers.showCityPicker(
//       context: context, locationCode: state.city_area_num_id.toString());
//   if (tempResult != null) {
//     logic.selectCity(tempResult);
//   }
// }
}
